﻿using BingWallpaper.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace BingWallpaper.Common
{
    public static class BingHelper
    {

        public static HPImageArchiveModel DownloadJson(int i=0)
        {
            using (WebClient webClient = new WebClient())
            { 
                Console.WriteLine("下载json...");
                webClient.Encoding = System.Text.Encoding.UTF8;
                string jsonString = webClient.DownloadString($"https://www.bing.com/HPImageArchive.aspx?format=js&idx={i}&n=1&mkt=zh-cn");
                return JsonConvert.DeserializeObject<HPImageArchiveModel>(jsonString);
            }
        }

    }
}
